<template>
  <div class="body" v-loading="loading.status">
    <div class="table-card">
      <el-table
        class="table"
        :data="tableData.data"
        :row-class-name="tableRowClassName"
        :border="true"
        size="mini"
      >
        <el-table-column prop="id" label="ID"> </el-table-column>
        <el-table-column prop="nickname" label="管理员名字"> </el-table-column>
        <el-table-column prop="ip" label="登录IP"> </el-table-column>
        <el-table-column prop="createtime" label="登录时间"> </el-table-column>
      </el-table>

      <el-pagination
        class="table_pagination"
        @size-change="handleTableSizeChange"
        @current-change="handleTableCurrentChange"
        :current-page="currentPage4"
        :page-sizes="$pageSize"
        :page-size="tableParams.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="tableData.total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { apiManageLoginLogs } from "@/api/apiSystem";
import { paramsDeleteNull } from "@/utils/common";
import { formatTimestamp } from "@/utils/datetimeUtil";
import { loading_start, loading_end } from "@/utils/loadingUtil";
export default {
  name: "Index",
  data() {
    return {
      tableParams: {
        page: 1,
        size: 15,
        business_uid: "",
        o_id: "",
        loan_type: "",
        push_status: "",
        entry_status: "",
        plan_name: "",
        status: "normal",
      },
      tableData: {
        current_page: 1,
        data: [],
        last_page: 1,
        per_page: "15",
        total: 0,
      },
      currentPage4: 1,
      business_select: [],
      organization_select: [],
      fromViewCofing: {
        input_width: "120px",
        label_width: "120px",
      },
      loading: {
        status: false,
        loadingCount: 0,
      },
    };
  },
  created() {
    this.loadTableData();
  },
  methods: {
    // 列表请求
    loadTableData() {
      const _this = this;
      loading_start(this);
      var tableParamsData = { ..._this.tableParams };
      tableParamsData = paramsDeleteNull(tableParamsData, "business_uid");
      apiManageLoginLogs(tableParamsData)
        .then((response) => {
          const result = response;
          var tableData = result.data.datalist;
          for (var i = 0; i < tableData.data.length; i++) {
            tableData.data[i]["createtime"] = formatTimestamp(
              tableData.data[i]["createtime"]
            );
          }
          console.log(tableData, "tableData");
          _this.tableData = tableData;
          loading_end(this);
        })
        .catch(function (result) {
          _this.$message.error(result.msg);
          _this.tableData.data = null;
        });
    },
    // 获取机构列表
    reqApiOrganization(business_uid) {
      const _this = this;
      loading_start(this);
      apiOrganizationSelects({
        page: 1,
        size: 99,
        business_uid: business_uid,
      }).then((response) => {
        const result = response.data;
        _this.organization_select = result.selects;
        loading_end(this);
      });
    },
    //切换商务人员
    changeSelectBusinessuid(business_uid) {
      this.tableParams.o_id = "";
      this.reqApiOrganization(business_uid);
    },
    // 页面跳转
    handleToGoCreate() {
      this.$router.push({ path: "/product/create", query: { id: 0 } });
    },
    // 表格行状态
    tableRowClassName({ row, rowIndex }) {
      if (row["status"] == "stop") {
        return "discard-row";
      }
    },
    // 表格操作
    handleTableEdit(index, row) {
      this.$router.push({ path: "/product/update", query: { id: row.id } });
    },
    // 表格恢复
    handleTableRegain(index, row) {
      var _this = this;
      var params = {
        id: row.id,
        status: "normal",
      };
      loading_start(this);
      apiProductUpdatePart(params).then((response) => {
        loading_end(this);
        _this.loadTableData();
      });
    },
    // 表格删除
    handleTableDelete(index, row) {
      const _this = this;
      loading_start(this);
      apiProductDelete({
        id: row.id,
      }).then((response) => {
        this.$message({
          message: response.msg,
          type: "success",
        });
        loading_end(this);
        _this.loadTableData();
      });
    },
    // 数量改变
    handleTableSizeChange(val) {
      this.tableParams.size = val;
      this.loadTableData();
    },
    // 页数改变
    handleTableCurrentChange(val) {
      this.tableParams.page = val;
      this.loadTableData();
      // console.log(`当前页: ${val}`);
    },
    // 部分状态改变
    tableUpdateItem(item) {
      var _this = this;
      var params = {
        id: item.id,
        push_status: item.push_status,
        entry_status: item.entry_status,
      };
      loading_start(this);
      apiProductUpdatePart(params).then((response) => {
        loading_end(this);
      });
    },
    // 开始加载
    loading_start() {
      const _this = this;
      if (_this.loading.loadingCount === 0) {
        // 显示加载状态
        _this.loading.status = true;
      }
      _this.loading.loadingCount += 1;
    },
    // 停止加载
    loading_end() {
      const _this = this;
      if (_this.loading.loadingCount > 0) {
        _this.loading.loadingCount -= 1;
        if (_this.loading.loadingCount === 0) {
          _this.loading.status = false;
        }
      }
    },
  },
};
</script>

<style lang="scss"></style>
